<!--
 * @Author: 汪军 624473119@qq.com
 * @Date: 2023-10-22 13:13:43
 * @LastEditors: 汪军 624473119@qq.com
 * @LastEditTime: 2023-10-30 09:55:41
 * @FilePath: \app-formwork\src\pages\login\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template lang="pug">
view.setting
  u-cell-group
    u-cell(v-for="(item, index) in moduleList", :title="item.name", :isLink="true", @click="onModule(item)")
  //- 退出账号提示框
  ModalBox(:data="modalData", @cancel="onModalBoxCancel", @confirm="onModalBoxConfirm")
</template>

<script setup>
import ModalBox from "@/components/modal-box/modal-box.vue";
import { loginApi } from "@/api/login.js";

const moduleList = ref([
  {
    name: "关于我们",
    type: 1,
    path: "/pagesB/about/about"
  },
  {
    name: "隐私政策",
    type: 2,
    path: "/pagesB/agreement/agreement?type=2"
  },
  {
    name: "用户协议",
    type: 3,
    path: "/pagesB/agreement/agreement?type=1"
  },
  {
    name: "修改密码",
    type: 4,
    path: "/pagesB/edit-password/edit-password"
  },
  {
    name: "退出账号",
    type: 5,
    path: ""
  }
]);
const modalData = ref({
  show: false,
  title: "是否选择退出?",
  btn1: "取消",
  btn2: "退出",
  type: 2
});

// 获取用户协议&&隐私政策
const onModule = (item) => {
  switch (item.type) {
    case 5:
      modalData.value.show = true;
      break;
    default:
      uni.navigateTo({ url: item.path });
      break;
  }
};

// 模态框操作
const onModalBoxCancel = () => {
  modalData.value.show = false;
};
const onModalBoxConfirm = () => {
  loginApi.loginout().then((res) => {
    modalData.value.show = false;
    uni.showToast({ title: res.msg, icon: "none" });
    uni.clearStorageSync();
    uni.navigateTo({ url: "/pages/login/index" });
  });
};
</script>

<style lang="scss" scoped>
::v-deep(.u-cell) {
  .u-cell__body {
    // border-bottom: 1px solid red;
    height: 112rpx;
    line-height: 112rpx;
  }
}
</style>
